from selenium import webdriver
from module import login
import time

print('test1 py启动')
option = webdriver.ChromeOptions()
# # options.add_argument('--headless')  # 无头模式，无界面运行（无窗口）
# #options.add_argument('--disable-gpu')
# option.add_argument('--disable-extensions')
# option.add_argument('--profile-directory=Default')
# option.add_argument("--incognito")  # 隐身模式
# option.add_argument("--disable-plugins-discovery");
# option.add_argument("--start-maximized")   #最大化运行（全屏窗口）
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# option.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
option.add_argument('disable-infobars')#浏览器不显示受自动测试软件控制
# 设置代理
option.add_argument("--proxy-server=http://127.0.0.1:8080")
driver = webdriver.Chrome(options=option)

# option = webdriver.FirefoxOptions()
# driver = webdriver.Firefox(options=option)
# 模拟登录
driver = login.login(None, None, driver)
# 前往指定直播间
driver.get('https://fm.missevan.com/live/133469515')

navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseEnd = driver.execute_script("return window.performance.timing.responseEnd")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
loadEventEnd = driver.execute_script("return window.performance.timing.loadEventEnd")

backendPerformance = responseEnd-navigationStart
domperformance = domComplete - responseEnd
frontendPerformance = loadEventEnd-responseEnd
FinisheTime = backendPerformance+frontendPerformance

print("backend",backendPerformance)
print("domperformance",domperformance)
print("domComplete",domComplete)
print("loadEventEnd",loadEventEnd)
# 开始机器人管理。

'''test功能
    发送弹幕。
'''
# 等待页面加载
time.sleep(4)
# input输入框
input = driver.find_element_by_xpath('//*[@id="Chatroom"]/div[4]/input')
# 发送按钮
'''修改为同步方法， 防止多线程情况下输入混乱。 包含发射弹幕。 统一封装'''
#send = driver.find_element_by_xpath('/html/body/app/div/div[2]/div[5]/div[2]/div/div[2]/div[2]/div[4]/button[2]')
# 模拟弹幕， hello
# #input.send_keys('hello')
# #print('发射弹幕。')
# send.click()
# print('done')
# time.sleep(10)
'''
    测试消息box ， 最多100条。
     
'''



#
# driver.get('https://fm.missevan.com/live/135945155')
# print(driver.title)
#
#
# myin = driver.find_element_by_xpath('//*[@id="Chatroom"]/div[3]/input')
# mysend = driver.find_element_by_xpath('//*[@id="Chatroom"]/div[3]/button[2]')
# myin.send_keys("hello")
# mysend.click()

# 关闭driver！！！！！
#driver.quit();